package org.lagou.dao;

import org.lagou.io.Resources;
import org.lagou.pojo.Student;
import org.lagou.sqlSeesion.SqlSession;
import org.lagou.sqlSeesion.SqlSessionFactory;
import org.lagou.sqlSeesion.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

//public class StudentDaoImpl implements IStudentDao {
public class StudentDaoImpl {

    // @Override
    public List<Student> findAllStudents() throws Exception {
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        List<Student> list = sqlSession.selectList("student.selectList");
        for (Student stu : list) {
            System.out.println(stu.getStu_id());
        }
        return list;
    }

    // @Override
    public Student findByCondition(Student student) throws Exception {

        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        Student student1 = sqlSession.selectOne("student.selectOne", student);
        System.out.println(student1.getStu_id());

        return student1;
    }

}
